package com.xlj.springbootmybatis.user.controller;

import com.xlj.springbootmybatis.user.entity.User;
import com.xlj.springbootmybatis.user.service.Userservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: xlj
 * @Description:springboot整合mybatis demo
 * @Date: Created in 16:15 2019\1\31 0031
 */
@RestController
public class UserController {

    @Autowired
    private Userservice userservice;

    @RequestMapping("/saveUser")
    public int saveUser(@RequestParam(value = "userName") String userName,
                         @RequestParam(value = "password") String password, Integer age){
        return  userservice.saveUser(userName, password, age);
    }

    @RequestMapping("/addUser")
    public int addUser(User user){
        return userservice.addUser(user);
    }

    @RequestMapping("/delUserByUserId")
    public int delUserByUserId(@RequestParam("userId") Integer userId){
        return userservice.delUserByUserId(userId);
    }

    @RequestMapping("/updateUserByUserId")
    public int updateUserByUserId(User user){
        return userservice.updateUserByUserId(user);
    }

    @RequestMapping("/getUserById")
    public User getUserById(@RequestParam(value = "userId") Integer userId){
        return userservice.getUserById(userId);
    }

    @RequestMapping("/getUserByUserName")
    public List<User> getUserByUserName(String userName){
        return userservice.getUserByUserName(userName);
    }

    @RequestMapping("/getUserList")
    public List<User> getUserList(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,  User user){
        return userservice.getUserList(pageNum, pageSize, user);
    }

}
